package com.aaa.sts.controller;

import com.aaa.common.entity.Station;
import com.aaa.common.util.BaseUtil;
import com.aaa.common.util.OssUtil;
import com.aaa.common.util.Result;
import com.aaa.common.vo.Page;
import com.aaa.common.vo.StationVO;
import com.aaa.sts.service.StationService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * (Station)表控制层
 *
 * @author makejava
 * @since 2025-09-18 14:57:00
 */
@RestController
@RequestMapping("station")
@Log4j2
public class StationController {
    /**
     * 服务对象
     */
    @Resource
    private StationService stationService;

    @PostMapping("uploadPic")
    public Result uploadPic(@RequestParam("pic") MultipartFile file){
        //调用工具类，进行上传
        return BaseUtil.success(OssUtil.uploadFile("store/images",file));
    }

    @GetMapping("selectStationStatus")
    public Result selectStationStatus(Integer storeId, Integer station){
        return BaseUtil.success(this.stationService.selectStationStatus(storeId,station));
    }

    @GetMapping("selectByStoreId")
    public Result queryByStoreId(Integer storeId) {
        return BaseUtil.success(this.stationService.queryByStoreId(storeId));
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 查询结果
     */
    @PostMapping("query")
    public Result queryByPage(@RequestBody Page<StationVO> page) {
        return BaseUtil.success(this.stationService.queryByPage(page));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("queryById")
    public Result queryById(Integer id) {
        return BaseUtil.success(this.stationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param station 实体
     * @return 新增结果
     */
    @PostMapping("insert")
    public Result add(@RequestBody Station station) {
        return BaseUtil.success(this.stationService.insert(station));
    }

    /**
     * 编辑数据
     *
     * @param station 实体
     * @return 编辑结果
     */
    @PostMapping("update")
    public Result edit(@RequestBody StationVO station) {
        return BaseUtil.success(this.stationService.update(station));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("delete")
    public Result deleteById(Integer id) {
        return BaseUtil.success(this.stationService.deleteById(id));
    }

}

